package pers.cz.postgirl.core;

import javassist.CannotCompileException;
import javassist.CtMethod;
import pers.cz.postgirl.config.EvenType;
import pers.cz.postgirl.util.JefLog;

/**
 * @program: postgirl-client
 * @description: CtMethod扩展类
 * @author: Cheng Zhi
 * @create: 2023-05-23 14:39
 **/
public class CtMethodWrapper {

    public static JefLog jefLog = new JefLog(CtMethodWrapper.class);

    private CtMethod ctMethod;

    public CtMethodWrapper(CtMethod ctMethod) {
        this.ctMethod = ctMethod;
    }

    public void enhance(EvenType evenType, String src) throws CannotCompileException {
        switch (evenType) {
            case AFTER:
                ctMethod.insertAfter(src);
                return;
            case BEFORE:
                ctMethod.insertBefore(src);
                return;
            case THROW:
                jefLog.debug("暂时不支持异常插入");
                return;
        }
    }
}
